// components/emojikeyboard/emojikeyboard.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    //是否显示键盘
    isKeyboard: {
      type: Boolean,
      value: false
    },
  },

  /**
   * 组件的初始数据
   * keyboard1:首页键盘,显示表情包
   */
  data: {
    keyboardChi:
      ["\ud83d\ude0a", "\u263a", "\ud83c\udfb8", "\ud83d\ude1c", "\ud83d\ude33", "\ud83c\udfa4", "\ud83d\ude02", "\ud83d\ude2d", "\ud83d\ude31", "\ud83d\ude24", "\ud83d\ude06", "\ud83d\ude0e", "\ud83d\ude08", "\ud83d\ude0f", "\ud83d\ude3b", "\ud83d\udc7d", "\ud83d\ude0d", "\ud83d\udd25", "\ud83d\udc40", "\u270a", "\ud83d\udc4b", "\ud83d\ude4c", "\ud83d\udc4f", "\ud83d\udcaa", "\ud83d\udc98", "\ud83e\udd41", "\ud83d\ude43", "\ud83c\udf7b", "\ud83e\udd29", "\ud83d\udc7b", "\ud83c\udf1d", "\ud83d\ude07", "\ud83e\udd1f", "\ud83e\udd80", "\ud83d\udcab", "\ud83c\udf1f", "\ud83c\udf0a", "\ud83c\udf7b", "\ud83c\udf77", "\ud83e\udd42", "\ud83c\udf88", "\ud83c\udf1d", "\ud83c\udf8a", "\ud83c\udf89", "\u2764\ufe0f", "\ud83d\udc97", "\ud83d\udcaf","删除"],
    keyboardSpe: ['del', 'ok'],
    keyboardSpeFor: ['删除', '完成'],
    keyboardValue: [],
    maxLength: 6,
    errMsg: '更新表情数据出错，将使用默认表情信息'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 显示键盘
     */
    showKeyboard: function () {
      this.setData({
        isKeyboard: true
      });
    },
    /**
     * 隐藏键盘
     */
    hideKeyboard: function () {
      if (this.data.isKeyboard) {
        this.setData({
          isKeyboard: false
        })
      }
    },
    /**
     * 点击键盘按键事件
     */
    tapKeyboard: function (e) {
      var tapVal = e.target.dataset.val;
      var keyboardValue = this.data.keyboardValue;
      var length = keyboardValue.length;
      // if (tapVal === 'del') {
      if (tapVal === '删除') {
        //点击删除
        if (length < 1) {
          return false;
        }

        keyboardValue.pop();
        this.setData({
          keyboardValue: keyboardValue,
        });

        this.triggerEvent('input', keyboardValue);
        return false;
      }
      if (tapVal === 'ok') {
        //点击ok
        this.hideKeyboard();
        this.triggerEvent('done', keyboardValue);
        return false;
      }
      if (length >= this.data.maxLength) {
        return false;
      }

      keyboardValue.push(tapVal);
      this.setData({
        keyboardValue: keyboardValue,
      });

      this.triggerEvent('input', keyboardValue);
      return false;
    },
    
    /**
     * 组织键盘点击事件冒泡到父容器
     */
    stopProp: function () {
      return false;
    }
  }
})

